/**
 * informationController Module
 *
 * InformationController
 */
angular.module('app.con.information', []).controller('InformationController', function($scope, $modal, InformationService) {
    // ngView部分高度自适应
    var window_height = window.innerHeight - document.getElementsByTagName('nav')[0].offsetHeight - document.getElementsByTagName('footer')[0].offsetHeight;
    document.getElementById('ngView').style.height = window_height + 'px';

    // datepicker实现函数，实现选择日期控件
    $scope.today = function() {
        $scope.dt = new Date(); // 定义一个属性来接收当天日期
    };
    $scope.today();
    $scope.clear = function() {
        $scope.dt = null;
    }
    $scope.open = function($event) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.opened = true;
    }
    $scope.disabled = function(date, mode) {
        return (mode === 'day' && (date.getDay() === 0 || date.getDay() === 6))
    }
    $scope.toggleMin = function() {
        $scope.minDate = $scope.minDate ? null : new Date();
    }
    $scope.toggleMin();
    $scope.dateOptions = {
        formatYear: 'yy',
        startingDay: 1
    }
    $scope.formats = ['dd-MMMM-yyyy', 'yyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
    $scope.format = $scope.formats[0];

    InformationService.list().success(function(res) {
        $scope.customers = res.information.customer;
    });
    $scope.shoppingList = function(name_id) {
        // $scope.list = name_id;
        InformationService.list().success(function(res) {
            $scope.purchase_histories = res.information.purchase_history;
            $scope.purchase_histories.forEach(function(list) {
                if(name_id == list.name_id) {
                    $scope.list = list;

                    var shoppingListModule = $modal.open({
                        templateUrl: 'shoppingList.html',
                        controller: 'shoppingListController',
                        resolve: {
                            list: function() {
                                return $scope.list;
                            }
                        }
                    });
                };
            });
        });
    };
});

angular.module('app.con.shoppingList', []).controller('shoppingListController', function($scope, list) {
    $scope.list = list;
    $scope.shopping_lists = $scope.list.shopping_list;
});
